import request from "./request";
import type { BaseResponse, LoginResponse, UserListItem, UserListParams, UserListResponse } from "./type";

// 登录
export const loginApi = async () => {
  try {
    const res = await request.post<LoginResponse>('/login', { username: '123', password: '123' })
    // console.log(res)
    if (res.data.code === 0) {
      localStorage.token = res.data.token
      alert(res.data.msg)
    } else
    alert('登录失败: ' + res.data.msg)
  } catch (error) {
    console.log(error)
  }
}
// 用户列表
export const userListApi = (params: UserListParams) => request.get<UserListResponse>('/userlist', { params })
// 删除用户
export const removeUserApi = (id: string) => request.post<BaseResponse>('/user/delete', { id })
// 添加用户
export const createUserApi = (params: UserListItem) => request.post<BaseResponse>('/user/create', params)
// 编辑用户
export const updateUserApi = (params: UserListItem) => request.post<BaseResponse>('/user/update', params)
